// Components/controlLineWidth/controlLineWidth.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    cndUrl:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    cWidth:0,
    pwidth:0,
    percentage:50,

    sx:0,
    mx:0,
    areaNum:10,

    

  }, 
  pageLifetimes: {
    show: function () {
      
    }
  },  
  ready(){
    // var query = wx.createSelectorQuery();

    // query.select('.controlOutbox').boundingClientRect(function (rect) {
    //   console.log(rect)
    // }).exec();
    // 页面被展示
    console.log("页面被展示")
    var _this = this;
    var query = wx.createSelectorQuery().in(this);

    query.select('.controlOutbox').boundingClientRect(function (rect) {
      console.log(rect)
      var percentage = parseInt((rect.width / 2))
      _this.setData({
        cWidth: rect.width,
        pwidth: rect.width / 2
      })
    }).exec();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    start(e){
      console.log(e)
      var sx = e.touches[0].pageX
      this.setData({
        sx:sx,
        mx:sx
      })
      
    },
    move(e){
      var _this = this;
      var mx = e.touches[0].pageX
      var cWidth = this.data.cWidth;
      var pwidth = this.data.pwidth + (mx-this.data.sx);
      pwidth = pwidth <= 0 ? 0 : pwidth;
      pwidth = pwidth > cWidth ? cWidth : pwidth;

      var percentage = parseInt((pwidth / cWidth) * 100)
      this.setData({
        mx: mx,
        sx: mx,
        pwidth: pwidth,
        percentage: percentage
      })
      var areaNum = parseInt((pwidth / cWidth) * this.data.areaNum);
      areaNum = areaNum < 0 ? 0 : areaNum;
      this.triggerEvent("careafn", areaNum)
    }
  }
})
